<?php
session_start();
require '../../../php/database_login.php';

$sql = "select max(`id`) from `multipack_brief`";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);

$pack_id = 'PACK_' . (1000 + $row['max(`id`)'] + 1);
$date = date("Y-m-d");
$arr_temp = explode('/', $_POST['b_f']['back']);
$back = $arr_temp[count($arr_temp) - 1];
$arr_temp = explode('/', $_POST['b_f']['front']);
$front = $arr_temp[count($arr_temp) - 1];

$sql1 = "insert into `multipack_brief`(`pack_id`,`back`,`front`) values ('{$pack_id}','{$back}','{$front}')";
if (mysqli_query($conn, $sql1)) {
    foreach ($_POST['img'] as $i) {
        $arr_temp = explode('/', $i['pic']);
        $pic = $arr_temp[count($arr_temp) - 1];
        $sql2 = "insert into `multipack_detail`(`pack_id`,`pic`,`position`,`rotate`,`order`,`id_name`) values ('{$pack_id}','{$pic}','{$i['position']}','{$i['rotate']}','{$i['order']}','{$i['id_name']}')";
        mysqli_query($conn, $sql2);
    }
    echo "success";
} else {
    echo 'fail';
}

// echo json_encode($_POST['img']);
